<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->
<title>选择用户</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<jsp:include page="../common/import.jsp"></jsp:include>

</head>
<body>


<div class="modal-bg-white">
                
            <div class="modal-body">        
                <div class="search-head">
                    <div class="search-title">查询条件</div>
                    <div class="modal-open"><span class="font12">收起</span><i class="fa fa-angle-down ml5"></i></div>
                </div>
                <form id="_query_form" onSubmit="return false;" >
                <ul class="ser_ul modal-input-ul">
				  
                    <li style="width:50%;">
                    <label class="ser_tit">机构：</label> 
					<input type="text" class="inputText modal-input" id="s_unitName" name="unitName" value="" readOnly/>
					<input id="s_unitId" name="unitId" hidden="hidden" value="" type="text">	
					
                    </li>
                    <li style="width:50%;">
                       <label class="ser_tit">用户名：</label>
                       <input type="text" class="inputText modal-input" id="s_userName" name="userName" value="" />
                    </li>
                </ul>
			</form> 
			
			<span id="showCheckedUser">
						<em class="text-red mr5">已勾选：</em>
			</span>
					  
           <div id="userTable">
           
           </div>
            </div>
</div>

     <div id="treediv" style='top:75px;left:50px;overflow:scroll;display:none; position:absolute;width:300px;height:200px;background-color:#eeffdd; border:1px solid #BEC0BF;padding:5px;font-size:12px;'>
     
		<a onclick="hidetreediv();" href="#" class="link-red mr5" style="cursor:pointer;color:red;text-align:right;"><i class="fa fa-close"></i>取消</a>
		<ul id="tree" class="ztree"></ul>
	</div>
		   
</body>
<script type="text/javascript">

pageContentDiv = "#userTable";
queryUrl = '${ctx}/role/query/user';

$(function(){
	$("#s_unitName").focus(function() {
		var divObj = $("#treediv");
    	var txtObj = $("#s_unitName");
    	showDiv(divObj,txtObj,unitsetting,"${ctx}/user/getUnit");
    	
	});
	
	jumpPage(1);
	
	/* 搜素条件收起和展开 */
	var count = 0;
    $(".modal-open").click(function(){
        count++;
        var i = count%2;
        if(i == 0 ){
            $(".modal-input-ul").slideDown();
            $(".modal-open").text('收起').append('<i class="fa fa-angle-up ml5"></i>');
        }
        if(i == 1 ){
            $(".modal-input-ul").slideUp();
            $(".modal-open").text('展开').append('<i class="fa fa-angle-down ml5"></i>');
        }
    });
    
});


//点击选择用户
function clickUser(obj){
	var v = $(obj).val().split("_");
	var userId = v[0];
	var userName = v[1];
	if($(obj).is(':checked')){
		var html = "<span id='"+userId+"_"+userName+"' >"+userName+",</span>";
		$("#showCheckedUser").append(html);
	}else{
		var id = "#"+userId+"_"+userName;
		$(id).remove();
	}
}
function clickAll(obj){
	if($(obj).is(':checked')){
		//全选
		$("tr td input[type='checkbox']").each(function(index,o){
			if($(o).is(':checked')){
				//本来就够选了，不需要处理了
			}else{
				$(o).attr('checked','checked');
				clickUser(o);
			}
		});
	}else{
		//全不选
		$("tr td input[type='checkbox']").each(function(index,o){
			if($(o).is(':checked')){
				$(o).attr('checked',false);
				clickUser(o);
			}else{
				
				//本来就没够选了，不需要处理了
			}
		});
	}
}
/**
 * 上下页时，检查表格中记录是否曾经被勾选过
 */
function checkTableList(){
	$("#showCheckedUser span").each(function(index,obj){
		var userId =$(obj).attr('id').split('_')[0];
		var _id = '#'+userId;
		$(_id).attr('checked','checked');
	});
}
//确定用户
function comfireUser(){
	var user = '';
	$("#showCheckedUser span").each(function(index,obj){
		if(index == 0){
			user = user+$(obj).attr('id');
		}else{
			user = user+","+$(obj).attr('id');
		}
	});
	//alert(user);
	if(user != null && user != ''  ){
		window.parent.addUser(user);
	}
	setInterval("parent.layer.close(parent.layer.getFrameIndex(window.name))",100);
}

</script>
</html>